package top.lingkang.fas.common.utils;

/**
 * @author lingkang
 * created by 2025/7/20 0:58
 */
public class CommonUtils {
    private static Boolean isDev_ = null;

    /**
     * 判断当前运行环境是否是ide开发环境
     */
    public static boolean isIdeDevTool() {
        if (isDev_ != null)
            return isDev_;
        String classpath = System.getProperty("java.class.path");
        if (classpath.contains("idea_rt.jar") || classpath.contains("org.eclipse.jdt.core_")
                || classpath.contains("vscode-java") || classpath.contains("jdt.ls")) {
            isDev_ = true;
            return isDev_;
        }
        if (System.getenv("IDEA_HOME") != null || System.getenv("ECLIPSE_HOME") != null
                || System.getenv("VSCODE_IPC_HOOK") != null) {
            isDev_ = true;
            return isDev_;
        }
        // 检查是否存在VSCode设置的特定属性
        String vscodeProperty = System.getProperty("vscode.java.home");
        if (vscodeProperty != null && !vscodeProperty.isEmpty()) {
            isDev_ = true;
            return isDev_;
        }

        try {// idea
            Class.forName("com.intellij.rt.execution.application.AppMainV2");
            isDev_ = true;
            return true;
        } catch (ClassNotFoundException e) {
        }
        try {// eclipse
            Class.forName("org.eclipse.jdt.internal.junit.runner.RemoteTestRunner");
            return true;
        } catch (ClassNotFoundException e) {
        }

        isDev_ = false;
        return isDev_;
    }
}
